import React, { Component } from 'react'
import {Form,Input,Button,Checkbox,message } from "antd"
import axios from "axios"
export class Login extends Component {
  onFinish(values){
    axios.get("/toLogin",values).then((res)=>{
      if(res.data.code===200){
        message.success("登录成功")
        localStorage.setItem("user",JSON.stringify(values))
        this.props.history.push("dash/fenxi")
      }else{
        message.error("登录失败")
      }
    })
  }
  onFinishFailed(){
    me
  }
  render() {
    return (
      <div className='login'>
        <div className='loginCont'></div>
        <Form
      name="basic"
      labelCol={{ span: 8 }}
      wrapperCol={{ span: 16 }}
      initialValues={{ remember: true }}
      onFinish={onFinish}
      onFinishFailed={onFinishFailed}
      autoComplete="off"
    >
      <Form.Item
        label="用户名"
        name="username"
        rules={[{ required: true, message: '请输入用户名' }]}
      >
        <Input />
      </Form.Item>

      <Form.Item
        label="密码"
        name="password"
        rules={[{ required: true, message: '请输入密码' }]}
      >
        <Input.Password />
      </Form.Item>

      <Form.Item name="remember" valuePropName="checked" wrapperCol={{ offset: 8, span: 16 }}>
        <Checkbox>Remember me</Checkbox>
      </Form.Item>

      <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
        <Button type="primary" htmlType="submit">
          Submit
        </Button>
      </Form.Item>
    </Form>

      </div>
    )
  }
}

export default Login